package packge.io;

import java.io.*;

class SerTest {
	public static void main(String str[]) throws Exception {
		Address add = new Address(456);
		Student stud = new Student("sri", "srnivas", "javasree", 99, "sri@jlc.com", 998762, 4500, add);
		Student stud1 = new Student("Manish", "manish", "jlcindia", 88, "manish@jlc.com", 765434565, 1200, add);
		System.out.println(stud);
		Student.numberOfBranch = 3;
		Student.fullCourseFee = 13000.0F;
		Student.insName = "SDSOFT";
		System.out.println("-- After modifying static values --");
		System.out.println(stud);
		FileOutputStream fos = new FileOutputStream("studinfo.ser");
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeInt(Student.numberOfBranch);
		oos.writeFloat(Student.fullCourseFee);
		oos.writeObject(Student.insName);
		oos.writeObject(stud.pwd);
		oos.writeObject(stud);
		oos.writeObject(stud1);
	}
}

class DeserTest {
	public static void main(String str[]) throws Exception {
		FileInputStream fis = new FileInputStream("studinfo.ser");
		ObjectInputStream ois = new ObjectInputStream(fis);
		System.out.println(ois.readInt());
		System.out.println(ois.readFloat());
		System.out.println(ois.readObject());
		System.out.println(ois.readObject());
		System.out.println("-----------------------------------------------------");
		Object obj = ois.readObject();
		Student st = (Student) obj;
		System.out.println(st);
		obj = ois.readObject();
		st = (Student) obj;
		System.out.println(st);
	}
}

class Person {
	String name = "XXXX";

	Person(String name) {
		this.name = name;
	}

	Person() {
		System.out.println("--- Person() ---");
	}
}

class User extends Person implements Serializable {
	String uname;
	transient String pwd = "tytyty";

	User(String name, String uname, String pwd) {
		super(name);
		this.uname = uname;
		this.pwd = pwd;
	}

	User() {
		System.out.println("-- User() ---");
	}
}

class Student extends User {
	int sid;
	String email;
	long phone;
	transient float fee;
	static int numberOfBranch = 5;
	static float fullCourseFee = 16000.0F;
	static String insName = "Java Learning Center";
	transient Address studAddress;

	Student() {
		System.out.println("--- Student() ---");
	}

	Student(String name, String uname, String pwd, int sid, String email, long phone, float fee, Address add) {
		super(name, uname, pwd);
		this.sid = sid;
		this.email = email;
		this.phone = phone;
		this.fee = fee;
		this.studAddress = add;
		System.out.println("--- Student params Cons ---");
	}

	public String toString() {
		return name + "\t" + sid + "\t" + email + "\t" + phone + "\t" + fee + "\t" + numberOfBranch + "\t"
				+ fullCourseFee + "\t" + insName + "\nUser:\t" + uname + "\t" + pwd + "\nAdd:\t" + studAddress;
	}
}

class Address {
	int aid;

	Address(int aid) {
		this.aid = aid;
	}

	public String toString() {
		return aid + "";
	}
}